package com.hearwego.utilities;

import java.text.NumberFormat;
import java.util.Locale;

import com.hearwego.R;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


public class GastosAdapter extends BaseAdapter {
    private Activity activity;
    private String[] dataIdGasto,dataIdLista,dataDescripcion,dataMonto,dataDate;
    private static LayoutInflater inflater = null;
    public GastosAdapter(Activity a, String[] idgasto,String[] idlista,String[] descripcion,String[] monto,
                    String[] date) {
            int tam=idgasto.length;
            dataIdGasto=new String[tam];
            dataIdLista=new String[tam];
            dataDescripcion=new String[tam];
            dataMonto=new String[tam];
            dataDate=new String[tam];
            
            //inicializar falta
            activity = a;
            dataIdGasto = idgasto;
            dataIdLista=idlista;
            dataDescripcion=descripcion;
            dataMonto=monto;
            dataDate=date;
            inflater = (LayoutInflater) activity
                            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public int getCount() {
            //El tamaño es el mismo para cualquier arreglo, dataMarca o cualquier otro da lo mismo
            return dataIdGasto.length;
    }

    public Object getItem(int position) {
            return position;
    }

    public long getItemId(int position) {
            return position;
    }

    public static class ViewHolder {
            public TextView txtdescr;
            public TextView txtmonto;
            public TextView txtdate;

    }

    public View getView(int position, View convertView, ViewGroup parent) {
            View vi = convertView;
            ViewHolder holder;
            if (convertView == null) {
                    vi = inflater.inflate(R.layout.item_gasto, null);
                    holder = new ViewHolder();

                    holder.txtdescr = (TextView) vi
                                    .findViewById(R.id.txt_gasto);
                    
                    holder.txtmonto = (TextView) vi
                                    .findViewById(R.id.txt_monto);

                    holder.txtdate = (TextView) vi
                                    .findViewById(R.id.txt_date);
                    

                    
                    vi.setTag(holder);
            } else
                    holder = (ViewHolder) vi.getTag();
            
            //Usar arreglo[position] para esto
            NumberFormat nf = NumberFormat.getInstance();
            nf = NumberFormat.getInstance(Locale.ENGLISH);
            
            holder.txtdescr.setText(""+dataDescripcion[position]);
            
            holder.txtmonto.setText(""+dataMonto[position]);

            
            holder.txtdate.setText(""+dataDate[position]);

            return vi;
    }
//    public void tos(){
//    }
}
